﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ButtonInputMgr : MonoBehaviour
{
    [SerializeField] private ButtonData[] m_buttonData;
    [SerializeField] private CombinedOrMultiButtonData[] m_combinedButtonData;
    [SerializeField] private CombinedOrMultiButtonData[] m_multiButtonData;

    private Hashtable m_buttonHash = new Hashtable();

    private bool m_boolTemp;

    void Start()
    {
        for (int i = 0, length = m_buttonData.Length; i < length; i++)
        {
            m_buttonData[i].Init();
            m_buttonHash.Add(m_buttonData[i].ID, false);
        }

        for (int i = 0, length = m_combinedButtonData.Length; i < length; i++)
        {
            m_combinedButtonData[i].Init();
        }

        for (int i = 0, length = m_multiButtonData.Length; i < length; i++)
        {
            m_multiButtonData[i].Init();
        }
    }

    void Update()
    {
        Detect();
        CheckCombined();
        CheckMulti();
    }

    private void Detect()
    {
        for (int i = 0, length = m_buttonData.Length; i < length; i++)
        {
            m_buttonHash[m_buttonData[i].ID] = m_buttonData[i].Detect();
        }
    }

    private void CheckMulti()
    {
        for (int i = 0, length = m_multiButtonData.Length; i < length; i++)
        {
            m_multiButtonData[i].CheckMulti(m_buttonHash);
        }
    }

    private void CheckCombined()
    {
        for (int i = 0, length = m_combinedButtonData.Length; i < length; i++)
        {
            m_combinedButtonData[i].CheckCombined(m_buttonHash);
        }
    }
}
